# socket tcp client
import socket
# 创建socket
client = socket.socket()
print(client)

help(client.connect)
# 连接远程服务
client.connect(('127.0.0.1', 9999))
print(client)

help(client.send)

try:
    while True:
        msg = input('input msg : ')
        # 发送数据
        client.send(f'{msg}\n'.encode()) # 字符串encode为二进制数据，对于python来说英文展示形式为b'xxx'
        if msg == 'exit':
            print('bye bye')
            break
        # 接收数据
        data = client.recv(1024)
        print('server reply ->', data)
except Exception as e:
    raise e
finally:
    # 关闭socket
    client.close()